package org.csu.mypetstore.service;

import org.csu.mypetstore.domain.Account;
import org.csu.mypetstore.domain.Order;
import org.csu.mypetstore.domain.Product;
import org.csu.mypetstore.persistence.OrderMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrderService {
    @Autowired
    OrderMapper orderMapper;

    public List<Order> getOrderList() {return orderMapper.orderList();}
    public void updateOrder (Order order){orderMapper.updateOrder(order);}
    public void updateAccount (Account account){orderMapper.updateAccount(account);}
    public void send (String name){orderMapper.send(name);}
    public List<Product> getProductListByOrderId(String orderId){return orderMapper.getProductListByOrderId(orderId);}
    public String getProductIdByItemId(String itemId){return orderMapper.getProductIdByItemId(itemId);}
    public String getCategoryIdByProductId(String productId){return orderMapper.getCategoryIdByProductId(productId);}
    public String getUserIdByOrderId(String orderId){return orderMapper.getUserIdByOrderId(orderId);}
    public List<Order>searchOrderByAddr(String addr) {return orderMapper.searchOrderByAddr("%" + addr.toLowerCase() + "%");}
    public List<Order>searchOrderByUser (String userId){return orderMapper.searchOrderByUser("%" + userId.toLowerCase() + "%");}
    public List<Order>searchOrderByBoth (String addr, String userId){return orderMapper.searchOrderByBoth("%" + addr.toLowerCase() + "%", "%" + userId.toLowerCase() + "%");}
    public void deleteOrders (String orderId){orderMapper.deleteOrders(orderId);}
    public void deleteOrderstatus (String orderId){orderMapper.deleteOrderstatus(orderId);}
    public void deleteLineItem (String orderId){orderMapper.deleteLineItem(orderId);}
}
